<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>

    //访问对象两种形式
    var person ={
        personName:"zhangsan",
        age:20,
        sayHello:function(){
            console.log("hello");
        }
    }

    //1.最常用：对象.属性名/对象.方法名
    console.log(person.age);
    person.sayHello();
    //2.对象["属性名"]
    console.log(person["personName"]);
    person["sayHello"]();

    //区别：对象[变量] 2中括号可以存放变量
    var attr = "age";
    console.log(person[attr]);

    //访问对象中不存在的属性，得到undefined
    //console.log(person.hobby);

    //添加属性值：直接给新加上的属性赋值
    person.hobby = ["swimming","study"];
    console.log(person.hobby);
    //添加一个weight
    person["weight"] = "50kg";
    console.log(person["weight"]);

    //修改属性值(重新赋值)
    person.age = 30;
    person["age"] = 30;
    console.log(person.age);

    //删除属性值
    delete person.age;
    console.log(person.age);//undefined

    //接收的用户输入会作为prompt的返回值
    //如果用户取消，返回值为null
    var p1 = window.prompt("请输入用户姓名：","文本框默认值");
    console.log(p1);
</script>
</html>